home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Acere (Card Game) / AcereÄ.sit / Acereƒ / AcereApp.cp < prev    next >
Text File  |  1994-08-25  |  6KB  |  229 lines

  1. // ===========================================================================
  2. //    AcereApp.cp                    ⌐1994 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    A simple Application class which manages text documents.
  6.  
  7. #include "AcereApp.h"
  8. #include "CTextDoc.h"
  9. #include "CardWell.h"
  10. #include "CardDeck.h"
  11.  
  12. #include "WellDeck.h"
  13. #include "WellFreeCell.h"
  14. #include "WellStack.h"
  15.  
  16. #include <LApplication.h>
  17. #include <LGrowZone.h>
  18. #include <LWindow.h>
  19. #include <LScroller.h>
  20. #include <LPrintout.h>
  21. #include <LPlaceHolder.h>
  22.  
  23. #include <UMemoryMgr.h>
  24. #include <UDrawingState.h>
  25. #include <UPowerTools.h>
  26. #include <URegistrar.h>
  27. #include <UDesktop.h>
  28.  
  29.             AcereApp    *theApp;
  30. extern        CTextDoc    *theDoc;
  31.  
  32. // ===========================================================================
  33. //        Ñ Main Program
  34. // ===========================================================================
  35.  
  36. void main(void)
  37. {
  38.                                     // Set Debugging options
  39. #ifdef Debug_Throw
  40.     gDebugThrow = debugAction_Alert;
  41. #endif
  42.  
  43. #ifdef Debug_Signal
  44.     gDebugSignal = debugAction_Alert;
  45. #endif
  46.  
  47.     InitializeHeap(3);                // Initialize Memory Manager
  48.                                     // Parameter is number of Master Pointer
  49.                                     //   blocks to allocate
  50.     
  51.                                     // Initialize standard Toolbox managers
  52.     UQDGlobals::InitializeToolbox(&qd);
  53.     
  54. #ifdef Debug_Signal                    // Check for missing MBAR, which
  55.     CheckForInitialMBAR();            // probably means that there is no
  56. #endif                                // project resource file
  57.     
  58.     
  59.     new LGrowZone(20000);            // Install a GrowZone function to catch
  60.                                     //    low memory situations.
  61.                                     //    Parameter is size of reserve memory
  62.                                     //    block to allocated. The first time
  63.                                     //    the GrowZone function is called,
  64.                                     //    there will be at least this much
  65.                                     //    memory left (so you'll have enough
  66.                                     //    memory to alert the user or finish
  67.                                     //    what you are doing).
  68.     
  69.     theApp = new AcereApp;            // Create instance of your Application
  70.     theApp->Run();                    //   class and run it
  71. }
  72.  
  73.  
  74. // ===========================================================================
  75. //        Ñ AcereApp Class
  76. // ===========================================================================
  77.  
  78. // ---------------------------------------------------------------------------
  79. //        Ñ AcereApp
  80. // ---------------------------------------------------------------------------
  81. //    Constructor
  82.  
  83. AcereApp::AcereApp()
  84. {
  85.     short    i;
  86.  
  87.     theDoc = nil;
  88.     
  89.     for (i=0; i<4; i++)                            //    load up the patterns
  90.     {
  91.         suitPats[i][0] = GetCIcon(1000+i);
  92.         suitPats[i][1] = GetCIcon(1100+i);
  93.     }
  94.  
  95.         // Register classes for objects created from 'PPob' resources
  96.     URegistrar::RegisterClass('wind', (ClassCreatorFunc) LWindow::CreateWindowStream);
  97.     URegistrar::RegisterClass('scrl', (ClassCreatorFunc) LScroller::CreateScrollerStream);
  98. //    URegistrar::RegisterClass('Dtxt', (ClassCreatorFunc) CDirtyText::CreateDirtyTextStream);
  99.     URegistrar::RegisterClass('plac', (ClassCreatorFunc) LPlaceHolder::CreatePlaceHolderStream);
  100.     URegistrar::RegisterClass('prto', (ClassCreatorFunc) LPrintout::CreatePrintoutStream);
  101.     URegistrar::RegisterClass('view', (ClassCreatorFunc) CardWell::CreateCardWell);
  102.     URegistrar::RegisterClass('CWwl', (ClassCreatorFunc) WellFreeCell::CreateWellFreeCell);
  103.     URegistrar::RegisterClass('CWdk', (ClassCreatorFunc) WellStack::CreateWellStack);
  104.     URegistrar::RegisterClass('CWst', (ClassCreatorFunc) WellDeck::CreateWellDeck);
  105.     
  106.     
  107. //    ourDoc = (CTextDoc *)MakeNewDocument();
  108.     
  109. }
  110.  
  111.  
  112. // ---------------------------------------------------------------------------
  113. //        Ñ ~AcereApp
  114. // ---------------------------------------------------------------------------
  115. //    Destructor
  116.  
  117. AcereApp::~AcereApp()
  118. {
  119.         // +++ Add code here to cleanup (if necessary) before quitting
  120. }
  121.  
  122.  
  123. // ---------------------------------------------------------------------------
  124. //        Ñ ObeyCommand
  125. // ---------------------------------------------------------------------------
  126. //    Respond to commands
  127.  
  128. Boolean
  129. AcereApp::ObeyCommand(
  130.     CommandT    inCommand,
  131.     void        *ioParam)
  132. {
  133.     Boolean    cmdHandled = true;
  134.     
  135.     switch (inCommand) {
  136.     
  137.         // +++ Add cases here for the commands you handle
  138.         //        Remember to add same cases to FindCommandStatus below
  139.         //        to enable/disable the menu items for the commands
  140.     
  141.         default:
  142.             cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  143.             break;
  144.     }
  145.     
  146.     return cmdHandled;
  147. }
  148.  
  149.  
  150. // ---------------------------------------------------------------------------
  151. //        Ñ FindCommandStatus
  152. // ---------------------------------------------------------------------------
  153. //    Pass back status of a (menu) command
  154.  
  155. void
  156. AcereApp::FindCommandStatus(
  157.     CommandT    inCommand,
  158.     Boolean        &outEnabled,
  159.     Boolean        &outUsesMark,
  160.     Char16        &outMark,
  161.     Str255        outName)
  162. {
  163.     outUsesMark = false;
  164.     
  165.     switch (inCommand) {
  166.     
  167.         // +++ Add cases here for the commands you handle
  168.     
  169.         default:
  170.             LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  171.                                 outMark, outName);
  172.             break;
  173.     }
  174. }
  175.  
  176.  
  177. // ---------------------------------------------------------------------------
  178. //        Ñ OpenDocument
  179. // ---------------------------------------------------------------------------
  180. //    Open a Document file
  181.  
  182. void
  183. AcereApp::OpenDocument(
  184.     FSSpec    *inMacFSSpec)
  185. {
  186.     theDoc = new CTextDoc(this, inMacFSSpec);
  187. }
  188.  
  189.  
  190. // ---------------------------------------------------------------------------
  191. //        Ñ MakeNewDocument
  192. // ---------------------------------------------------------------------------
  193. //    Create a new Document
  194.  
  195. LModelObject*
  196. AcereApp::MakeNewDocument()
  197. {
  198.     if (theDoc == nil)
  199.     {
  200.         theDoc = new CTextDoc(this, nil);
  201.     }
  202.     else
  203.     {
  204.         theDoc->StartNewGame();
  205.     }
  206.     return theDoc;
  207. }
  208.  
  209.  
  210. // ---------------------------------------------------------------------------
  211. //        Ñ ChooseDocument
  212. // ---------------------------------------------------------------------------
  213. //    Prompt the user to select a document to open
  214.  
  215. void
  216. AcereApp::ChooseDocument()
  217. {
  218.     StandardFileReply    macFileReply;
  219.     SFTypeList            typeList;
  220.     
  221.     UDesktop::Deactivate();
  222.     typeList[0] = 'TEXT';
  223.     ::StandardGetFile(nil, 1, typeList, &macFileReply);
  224.     UDesktop::Activate();
  225.     if (macFileReply.sfGood) {
  226.         OpenDocument(&macFileReply.sfFile);
  227.     }
  228. }
  229.